module timer_change(
	input clk_51200Hz,
	input rst_n,
	input[5:0] minute,
	input[5:0] second,
	output reg[15:0] led_state
);

	integer i;
	reg[5:0] min;
	reg[5:0] sec;
	reg[15:0] led_temp;

	always @(posedge clk_51200Hz or negedge rst_n) begin
		if(rst_n == 1'b0) begin
			min = 6'd0;
			sec = 6'd0;
			led_temp = 16'd0;
			led_state = 16'd0;
		end
		else begin
			led_temp = 16'd0;
			min = minute;
			sec = second;
			
			for(i = 0; i < 4; i = i+1) begin
				led_temp[7:6] = sec % 3;
				led_temp[15:14] = min % 3;
				if(i < 3) begin
					led_temp = led_temp >> 2;
					sec = sec / 3;
					min = min / 3;
				end
			end
			
			led_state = 16'd0;
			for(i = 0; i < 8; i = i+1) begin
				case (led_temp[1:0])
					2'b10: 	led_state = led_state | 16'b10000000_00000000;
					2'b01: 	led_state = led_state | 16'b00000000_10000000;
					default: led_state = led_state | 16'b00000000_00000000;
				endcase

				if(i < 7) begin
					led_temp = led_temp >> 2;
					led_state = led_state >> 1;
				end
			end
			
		end
	end

endmodule
